package com.expressage.service.impl;

import com.expressage.dao.PostDao;
import com.expressage.po.Post;
import com.expressage.service.PostService;
import com.expressage.vo.PostInfo;
import com.expressage.vo.PostVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Gt
 * 接单业务逻辑实现类
 */
@Service("postService")
public class PostServiceImpl implements PostService {

    @Autowired
    PostDao postDao;

    @Override
    public List<PostVO> findAll() {
        return postDao.findAll();
    }

    @Override
    public List<PostVO> findStaffidList(int staffid) {
        return postDao.findStaffidList(staffid);
    }

    @Override
    public PostVO findBypid(int pid) {
        return postDao.findBypid(pid);
    }

    @Override
    public PostVO findByodd(int odd) {
        return postDao.findByodd(odd);
    }

    @Override
    public boolean insert(Post post) {
        post.setPostday(new Timestamp(System.currentTimeMillis()));
        return postDao.insert(post)>0?true:false;
    }

    @Override
    public boolean delete(int[] arrays) {
        return postDao.delete(arrays)>0?true:false;
    }

    @Override
    public boolean update(Post post) {
        return postDao.update(post)>0?true:false;
    }

    @Override
    public List<PostInfo> findStatPie() {
        return postDao.findStat();
    }

    @Override
    public Map<String, List> findStatBar() {
        Map<String,List> map =new HashMap<>();
        List<PostInfo> list =postDao.findStat();
        List<String> names = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        for (PostInfo info:list) {
            names.add(info.getName());
            values.add(info.getValue());
        }
        map.put("names",names);
        map.put("values",values);
        return map;
    }

    @Override
    public PostInfo findByStaffid(int staffid) {
        return postDao.findByStaffid(staffid);
    }
}
